<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'/ukkepuk/source/php/classes/service/CalendarService.php'); 
	require_once($_SERVER['DOCUMENT_ROOT'].'/ukkepuk/source/php/classes/model/Kid.php'); 
    require_once($_SERVER['DOCUMENT_ROOT'].'/ukkepuk/source/php/classes/model/Calendar.php'); 
	

	header("Content-Type:text/xml");  
	$calendarService = new CalendarService();
	
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
	
	//dispatch kid is the major post file to handle save and load of kid creche info (add food, diper, read kid xml, ...)
	
	if($_POST['action'] == "readCalendarForKid"){
        echo $calendarService->readKidCalendarInfoXml($_POST['kidId'], $_POST['year'], $_POST['month']);
	}else if($_POST['action'] == "readNextCalendarDaysForKid"){
        echo $calendarService->readNextCalendarDaysForKidXml($_POST['kidId'], $_POST['numDays']);
    }else if ($_POST['action'] == "readKidsCommingToday"){
        echo $calendarService->readKidsCommingTodayXml();
    }else if ($_POST['action'] == "readKidsCommingInMonth"){
        echo $calendarService->readKidsCommingThisMonthXml();
    }else if($_POST['action'] == "addTime"){
		$calendar = new Calendar();
        $calendar->setDate($_POST['cDate']);
		$calendar->setStartTime($_POST['cStartTime']); //HH:MM
		$calendar->setEndTime($_POST['cEndTime']); //HH:MM
        $calendar->setKidsId($_POST['kidId']);
        
        $type = $_POST['addtype'];
        
        echo $calendarService->saveCalendarTimeForKid($calendar, $type)->toXml();
	}else if($_POST['action'] == "kidsCommingInWeek"){
        $datekey = $_POST['datekey'];
        echo $kidsMonth = $calendarService->readKidsCommingInWeekXml($datekey);
        
        
    }
	
    

?>